<template>
	<view class="cu-modal bottom-modal" :class="show?'show':''">
		<view class="cu-dialog">
			<view class="cu-bar bg-white">
				<view class="action text-gray" @tap="hideModal">取消</view>
				<view class="action text-blue" @tap="confirm">确定</view>
			</view>
			<picker-view @change="bindChange" class="picker-view">
				<picker-view-column>
					<view class="item" v-for="(item,index) in jobArray" :key="index">{{item.name}}</view>
				</picker-view-column>
				<picker-view-column>
					<view class="item" v-for="(item,index) in jobArray2" :key="index">{{item.name}}</view>
				</picker-view-column>
			</picker-view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "JobPicker",
		props: {
			show: {
				type: Boolean,
			}
		},
		data() {
			return {
				jobArray: [],
				jobArray2: [],

				firstValue: null,
				lastIndex: 0
			};
		},
		watch: {
			show(value) {
				value && this.getJobcate()
			}
		},
		methods: {
			hideModal() {
				this.$emit('close')
			},
			async getJobcate() {
				const {
					data
				} = await this.$http.Recruit.jobcate()

				this.jobArray = data
				this.jobArray2 = data[0].subclass
			},
			bindChange(e) {
				console.log(e.detail)
				if (!this.firstValue) {
					if (this.firstValue != e.detail.value[0]) {
						this.jobArray2 = this.jobArray[e.detail.value[0]].subclass

					}
				} else {
					this.firstValue = e.detail.value[0]
				}
				this.lastIndex = e.detail.value[1]
			},
			confirm() {
				this.$emit('confirm',this.jobArray2[this.lastIndex])
			}
		}
	}
</script>

<style lang="less" scoped>
	.picker-view {
		width: 750rpx;
		height: 600rpx;
		margin-top: 20rpx;
	}

	.item {
		height: 50px;
		align-items: center;
		justify-content: center;
		text-align: center;
	}
</style>
